package com.enjoyor.soa.traffic.frame.configure;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.ProviderConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.enjoyor.soa.traffic.frame.dubbo.DubboProperties;

@Configuration
@EnableConfigurationProperties({ DubboProperties.class })
public class DubboConfig {

    @Autowired
    private DubboProperties dubboProperties;

    @Bean
    public ApplicationConfig requestApplicationConfig() {
        return this.dubboProperties.getApplication();
    }

    @Bean
    public RegistryConfig requestRegistryConfig() {
        return this.dubboProperties.getRegistry();
    }

    @Bean
    public ProtocolConfig requestProtocolConfig() {
        return this.dubboProperties.getProtocol();
    }

    @Bean
    public ProviderConfig requestProviderConfig() {
        if (this.dubboProperties.getProvider()!=null) {
            return this.dubboProperties.getProvider();
        }
        return new ProviderConfig();     
    }
    
}
